#include "Lighting.h"

// Initialize the instance to null
Lighting* Lighting::m_LightingInstance = 0;

Lighting::Lighting(void)
{
}

Lighting::~Lighting(void)
{
}

Lighting* Lighting::GetInstance(void)
{
	// Create the singleton if it doesn't exist
	if(!m_LightingInstance)
		m_LightingInstance = new Lighting;

	// Return the singleton
	return m_LightingInstance;
}

void Lighting::DeleteLightingInstance(void)
{
	// If instance exist, delete it!
	if(m_LightingInstance)
	{
		delete m_LightingInstance;
		m_LightingInstance = NULL;
	}
}

void Lighting::InitLighting(IDirect3DDevice9* m_pD3DDevice)
{
	ZeroMemory( &dLighting, sizeof(D3DLIGHT9));

	// Set all the values for the light and specify the type
	dLighting.Type = D3DLIGHT_POINT;
	dLighting.Position = D3DXVECTOR3( 10.0f, 20.0f, 10.0f);
	dLighting.Diffuse.r = 0.1f;
	dLighting.Diffuse.g = 0.1f;
	dLighting.Diffuse.b = 0.1f;
	dLighting.Diffuse.a = 1.0f;
	dLighting.Ambient.r = 0.5f;
	dLighting.Ambient.g = 0.5f;
	dLighting.Ambient.b = 0.5f;
	dLighting.Ambient.a = 0.5f;
	dLighting.Specular.r = 0.1f;
	dLighting.Specular.g = 0.1f;
	dLighting.Specular.b = 0.1f;
	dLighting.Specular.a = 0.1f;
	dLighting.Attenuation1 = 0.1f;
	dLighting.Range = 40.0f;

	// Set and enable the light
	m_pD3DDevice->SetLight( 0, &dLighting);
	m_pD3DDevice->LightEnable( 0, TRUE);

	// Turn on the light
	m_pD3DDevice->SetRenderState( D3DRS_LIGHTING, TRUE);

	// Apply a fixed function shader
	m_pD3DDevice->SetRenderState( D3DRS_SHADEMODE, D3DSHADE_GOURAUD);

	// Set the general ambient light color
	m_pD3DDevice->SetRenderState( D3DRS_AMBIENT, 0xff7f7f7f);

	// Turn on Specular (reflection)
	m_pD3DDevice->SetRenderState( D3DRS_SPECULARENABLE, true);
}

void Lighting::Update(void)
{
}